package com.ProductionAndConsumption;

import java.util.LinkedList;

public class Store2 {
    LinkedList linkedListNum = new LinkedList();
    public void save(int num){
        synchronized (linkedListNum){
            if (linkedListNum.size()==10){
                try {
                    linkedListNum.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }else {
                linkedListNum.add(num);
                System.out.println("添加" + num);
                linkedListNum.notifyAll();
            }
        }
    }
    public void take(){
        synchronized (linkedListNum){
            if(linkedListNum.size() == 0){
                try {
                    linkedListNum.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }else {
                Object poll = linkedListNum.poll();
                System.out.println("取出" + poll);
                linkedListNum.notifyAll();
            }
        }
    }
}